import React from 'react'
import { Switch, Route, Redirect } from 'react-router-dom'
import { useSelector } from 'react-redux'
import { Spin } from 'antd'
import LayOutCon from '../layout/index';
import Login from '../views/login'

export default function RouterIndex() {
  const LoadingInfo = useSelector(state => state.LoadingInfo)

  return (
    <div>
      <Spin spinning={LoadingInfo} >
        <Switch>
          <Route path='/login' component={Login}></Route>
          <Route path='/' render={() => (localStorage.getItem('token') ? <LayOutCon /> : <Redirect to='/login'></Redirect>)}></Route>
        </Switch>
      </Spin>
    </div>
  )
}
